import axios from './request'
import {GET_COLUMNS,SIGNUP,POSTS} from './api'
export interface paramsProps  {
    currentPage?:string ,
    pageSize?:string,
    id?: string
}

export interface signupProps {
    
  email: string,
  nickName: string,
  password: string
}

// /api/columns/{id}/posts?currentPage={page}&pageSize={size}
// 第一种请求方式，这样不太方便
/* export const getColumns = ()=> {
    return axios.get(GET_COLUMNS)
} */

// 第二种请求方式，可以配置参数
// 发送请求, 获得专栏列表
export const getColumns = (param:paramsProps)=> {
   const {currentPage = '1',pageSize = '10'} = param

    return axios({
        url: GET_COLUMNS,
        method: 'get',
        params: {
            currentPage,
            pageSize
        }
    })
}

// 获取专栏详情,获取单个专栏
export const getDetailColumn = (param:paramsProps) => {
    const {currentPage = '1',pageSize = '10',id} = param
    return axios({
        url: `${GET_COLUMNS}/${id}`,
        method:'get',
        params: {
            currentPage,
            pageSize
        }
    })
}

// 获取专栏的文章列表
export const getPotList = (param:paramsProps) => {
    const {currentPage = '1',pageSize = '10',id} = param
    return axios({
        url:`${GET_COLUMNS}/${id}/posts`,
        method:'get',
        params: {
            currentPage,
            pageSize
        }
    })
}

export const signup = (param:signupProps) => {
    return axios({
        url: SIGNUP,
        method: 'post',
        data: param
    })
}

// 创建文章
export const createPosts = (param:any) => {
    return axios({
        url:POSTS,
        method: 'post',
        data: param
    })
}

export const editPost  =(id: string) => {
    return axios({
        url: `${POSTS}/${id}`,
        method: 'get'
    })
}